package javaer.starter.idea.window.component;

import javax.swing.*;

public class PomXmlTemplateTextArea {

    private JTextArea pomXmlTemplate;

    private JTextArea springBoot;

    public PomXmlTemplateTextArea(JTextArea springBoot, JTextArea pomXmlTemplate) {
        this.pomXmlTemplate = pomXmlTemplate;
        this.springBoot = springBoot;
        this.springBoot.append(getDefaultSpringBoot());
        this.pomXmlTemplate.append(getDefaultPomXml());
    }

    public String getPomXml() {
        return this.pomXmlTemplate.getText();
    }

    public String getSpringBoot() {
        return this.springBoot.getText();
    }

    private String getDefaultSpringBoot() {
        return "org.springframework.boot:spring-boot-starter-parent:2.7.9";
    }

    private String getDefaultPomXml() {
        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
                "         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" +
                "    <modelVersion>4.0.0</modelVersion>\n" +
                "\n" +
                "    <#if parent??>\n" +
                "        <parent>\n" +
                "            <groupId>${parent.groupId}</groupId>\n" +
                "            <artifactId>${parent.artifactId}</artifactId>\n" +
                "            <#if imRootPom>\n" +
                "                <version>${parent.version}</version>\n" +
                "            <#else>\n" +
                "                <version>${r\"${revision}\"}</version>\n" +
                "            </#if>\n" +
                "        </parent>\n" +
                "    </#if>\n" +
                "\n" +
                "    <#if imRootPom>\n" +
                "        <groupId>${groupId}</groupId>\n" +
                "    </#if>\n" +
                "    <artifactId>${artifactId}</artifactId>\n" +
                "    <#if imRootPom>\n" +
                "        <version>${r\"${revision}\"}</version>\n" +
                "    </#if>\n" +
                "    <name>${artifactId}</name>\n" +
                "    <#if imRootPom>\n" +
                "        <#if imStarterPom>\n" +
                "            <packaging>jar</packaging>\n" +
                "        <#else >\n" +
                "            <packaging>pom</packaging>\n" +
                "        </#if>\n" +
                "    </#if>\n" +
                "    <#if imRootPom>\n" +
                "        <description>${description}</description>\n" +
                "    </#if>\n" +
                "\n" +
                "    <#if properties??>\n" +
                "        <properties>\n" +
                "        <#list properties? keys as key>\n" +
                "            <${key}>${properties[key]}</${key}>\n" +
                "        </#list>\n" +
                "        </properties>\n" +
                "    </#if>\n" +
                "\n" +
                "    <#if modules?? && (modules?size > 0) >\n" +
                "        <modules>\n" +
                "            <#list modules as m>\n" +
                "                <module>${m}</module>\n" +
                "            </#list>\n" +
                "        </modules>\n" +
                "    </#if>\n" +
                "\n" +
                "    <#if imRootPom>\n" +
                "        <dependencyManagement>\n" +
                "            <dependencies>\n" +
                "                <#if modules?? && (modules?size > 0) >\n" +
                "                    <#list modules as m>\n" +
                "                        <dependency>\n" +
                "                            <groupId>${groupId}</groupId>\n" +
                "                            <artifactId>${m}</artifactId>\n" +
                "                            <#if imRootPom>\n" +
                "                                <version>${r\"${revision}\"}</version>\n" +
                "                            </#if>\n" +
                "                        </dependency>\n" +
                "                    </#list>\n" +
                "                </#if>\n" +
                "                <#if dependencyManagement??  && (dependencyManagement?size > 0)>\n" +
                "                    <#list dependencyManagement as d>\n" +
                "                        <dependency>\n" +
                "                            <groupId>${d.groupId}</groupId>\n" +
                "                            <artifactId>${d.artifactId}</artifactId>\n" +
                "                            <#if d.version??>\n" +
                "                                <version>${d.version}</version>\n" +
                "                            </#if>\n" +
                "                            <#if d.optional??>\n" +
                "                                <optional>${d.optional}</optional>\n" +
                "                            </#if>\n" +
                "                            <#if d.scope??>\n" +
                "                                <scope>${d.scope}</scope>\n" +
                "                            </#if>\n" +
                "                            <#if d.exclusions?? && (d.exclusions?size > 0)>\n" +
                "                                <exclusions>\n" +
                "                                    <#list d.exclusions as exclusion>\n" +
                "                                        <exclusion>\n" +
                "                                            <groupId>${exclusion.groupId}</groupId>\n" +
                "                                            <artifactId>${exclusion.artifactId}</artifactId>\n" +
                "                                        </exclusion>\n" +
                "                                    </#list>\n" +
                "                                </exclusions>\n" +
                "                            </#if>\n" +
                "                        </dependency>\n" +
                "                    </#list>\n" +
                "                </#if>\n" +
                "            </dependencies>\n" +
                "        </dependencyManagement>\n" +
                "    </#if>\n" +
                "    <dependencies>\n" +
                "        <#if dependencyModules?? && (dependencyModules?size > 0) >\n" +
                "            <#list dependencyModules as m>\n" +
                "                <dependency>\n" +
                "                    <groupId>${groupId}</groupId>\n" +
                "                    <artifactId>${m}</artifactId>\n" +
                "                    <#if imRootPom>\n" +
                "                        <version>${r\"${revision}\"}</version>\n" +
                "                    </#if>\n" +
                "                </dependency>\n" +
                "            </#list>\n" +
                "        </#if>\n" +
                "        <#if dependencies?? && (dependencies?size > 0)>\n" +
                "            <#list dependencies as d>\n" +
                "                <dependency>\n" +
                "                    <groupId>${d.groupId}</groupId>\n" +
                "                    <artifactId>${d.artifactId}</artifactId>\n" +
                "                    <#if d.version??>\n" +
                "                        <version>${d.version}</version>\n" +
                "                    </#if>\n" +
                "                    <#if d.optional??>\n" +
                "                        <optional>${d.optional}</optional>\n" +
                "                    </#if>\n" +
                "                    <#if d.scope??>\n" +
                "                        <scope>${d.scope}</scope>\n" +
                "                    </#if>\n" +
                "                    <#if d.exclusions?? && (d.exclusions?size > 0)>\n" +
                "                        <exclusions>\n" +
                "                            <#list d.exclusions as exclusion>\n" +
                "                                <exclusion>\n" +
                "                                    <groupId>${exclusion.groupId}</groupId>\n" +
                "                                    <artifactId>${exclusion.artifactId}</artifactId>\n" +
                "                                </exclusion>\n" +
                "                            </#list>\n" +
                "                        </exclusions>\n" +
                "                    </#if>\n" +
                "                </dependency>\n" +
                "            </#list>\n" +
                "        </#if>\n" +
                "    </dependencies>\n" +
                "    <build>\n" +
                "        <#if imRootPom>\n" +
                "            <pluginManagement>\n" +
                "                <plugins>\n" +
                "                    <plugin>\n" +
                "                        <groupId>org.apache.maven.plugins</groupId>\n" +
                "                        <artifactId>maven-compiler-plugin</artifactId>\n" +
                "                        <version>3.8.1</version>\n" +
                "                        <configuration>\n" +
                "                            <showWarnings>true</showWarnings>\n" +
                "                            <showDeprecation>false</showDeprecation>\n" +
                "                            <source>${r'${maven.compiler.source}'}</source>\n" +
                "                            <target>${r'${maven.compiler.target}'}</target>\n" +
                "                            <encoding>${r'${project.build.sourceEncoding}'}</encoding>\n" +
                "                        </configuration>\n" +
                "                    </plugin>\n" +
                "                    <plugin>\n" +
                "                        <groupId>org.apache.maven.plugins</groupId>\n" +
                "                        <artifactId>maven-source-plugin</artifactId>\n" +
                "                        <version>3.2.1</version>\n" +
                "                        <executions>\n" +
                "                            <execution>\n" +
                "                            <id>attach-sources</id>\n" +
                "                            <goals>\n" +
                "                                <goal>jar</goal>\n" +
                "                            </goals>\n" +
                "                        </execution>\n" +
                "                    </executions>\n" +
                "                </plugin>\n" +
                "                <plugin>\n" +
                "                    <groupId>org.apache.maven.plugins</groupId>\n" +
                "                    <artifactId>maven-javadoc-plugin</artifactId>\n" +
                "                    <version>3.1.1</version>\n" +
                "                    <configuration>\n" +
                "                        <additionalOptions>\n" +
                "                            <additionalOption>-Xdoclint:none</additionalOption>\n" +
                "                        </additionalOptions>\n" +
                "                    </configuration>\n" +
                "                    <executions>\n" +
                "                        <execution>\n" +
                "                            <id>attach-javadocs</id>\n" +
                "                            <goals>\n" +
                "                                <goal>jar</goal>\n" +
                "                            </goals>\n" +
                "                        </execution>\n" +
                "                    </executions>\n" +
                "                </plugin>\n" +
                "                </plugins>\n" +
                "            </pluginManagement>\n" +
                "        </#if>\n" +
                "        <#if imStarterPom>\n" +
                "            <plugins>\n" +
                "                <plugin>\n" +
                "                    <groupId>org.springframework.boot</groupId>\n" +
                "                    <artifactId>spring-boot-maven-plugin</artifactId>\n" +
                "                    <#if mainClass??>\n" +
                "                        <configuration>\n" +
                "                            <mainClass>${mainClass}</mainClass>\n" +
                "                        </configuration>\n" +
                "                    </#if>\n" +
                "                    <executions>\n" +
                "                        <execution>\n" +
                "                            <goals>\n" +
                "                                <goal>repackage</goal>\n" +
                "                            </goals>\n" +
                "                        </execution>\n" +
                "                    </executions>\n" +
                "                </plugin>\n" +
                "            </plugins>\n" +
                "        </#if>\n" +
                "    </build>\n" +
                "</project>";
    }
}
